﻿using Twi.COMMON.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace Twi.Test.COMMON.Core
{
    
    
    /// <summary>
    ///这是 EncryptionAlgorithmTest 的测试类，旨在
    ///包含所有 EncryptionAlgorithmTest 单元测试
    ///</summary>
    [TestClass()]
    public class EncryptionAlgorithmTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        // 
        //编写测试时，还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///GetMD5 的测试
        ///</summary>
        [TestMethod()]
        public void GetMD5Test()
        {
            //string str = "123456";
            //string expected = "E10ADC3949BA59ABBE56E057F20F883E";
            string str = "ADMIN";
            string expected = "C54063E2782B03E4BD1284CF2ACB60FD";
            string actual;
            actual = EncryptionAlgorithm.GetMD5(str);
            Assert.AreEqual(expected, actual);           
        }

        /// <summary>
        ///ToBase64String 的测试
        ///</summary>
        [TestMethod()]
        public void ToBase64StringTest()
        {
            string str = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.2)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));User Id=gzhgs;Password=gzhgs;";
            string actual = EncryptionAlgorithm.ToBase64String(str); 
            string expected = EncryptionAlgorithm.FromBase64String(actual); 
            Assert.AreEqual(expected, str);
        }

        [TestMethod]
        public void FTXH()
        {
            string str = "";
            string str2 ="";
            str2 = EncryptionAlgorithm.GetMD5(str);
            str2 = EncryptionAlgorithm.ToBase64String(str2);
            string pwd = str;
            pwd = EncryptionAlgorithm.GetMD5(pwd);
            pwd = EncryptionAlgorithm.ToBase64String(pwd);
            //QTQ0NTdGRTA0OTIwNzY1MzcwMTVCNzM1MEY3MzQ5NEU=
            //QjRCNTlENkU3N0IxRjQzQjJDOTA3NjhDNUREQTk5MTU=
            Assert.AreEqual(str2, pwd);
        }

        /// <summary>
        ///Base64CustomerEncode 的测试
        ///</summary>
        [TestMethod()]
        public void Base64CustomerEncodeTest()
        {
            string str = "xuzhihong";
            string encodeStr = EncryptionAlgorithm.Base64CustomerEncode(str); 
            string decodeStr = EncryptionAlgorithm.Base64CustomerDecode(encodeStr);
            Assert.AreEqual(str, decodeStr);
        }
    }
}
